package com.suoluo.zenadmin.dao.dest;

import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;

import com.suoluo.zenadmin.vo.dest.DestTraffic2VO;

@DAO
public interface DestTrafficDAO {

	@SQL("select * from tb_dest_traffic2 where dest_id=:1 and level=1")
	public List<DestTraffic2VO> findDestTrafficLevel1ByDestId(int destId);
	
	@SQL("insert into tb_dest_traffic2(name,content,dest_id,traffic_type,parent_id,level,lat,lng,enname) " +
			"values(:1.name,:1.content,:1.destId,:1.trafficType,:1.parentId,:1.level,:1.lat,:1.lng,:1.enname)")
	public void saveDestTrafficLevel(DestTraffic2VO traffic);
	
	@SQL("select * from tb_dest_traffic2 where dest_id=:1 and traffic_type=:2")
	public List<DestTraffic2VO> findDestTrafficByDestIdAndTrafficType(int destId,int trafficType);

	@SQL("select * from tb_dest_traffic2 where traffic_id=:1")
	public DestTraffic2VO findDestTraffic2ById(int trafficId);
	
	@SQL("update tb_dest_traffic2 set traffic_type=:2 where dest_id=:1 and traffic_type=:3")
	public void updateDestTrafficLevelTrafficType(int destId,int trafficType,int oldTrafficType);
	
	@SQL("update tb_dest_traffic2 set name=:1.name,content=:1.content,traffic_type=:1.trafficType," +
			"parent_id=:1.parentId,level=:1.level,lat=:1.lat,lng=:1.lng,enname=:1.enname where traffic_id=:1.trafficId")
	public void updateDestTraffic2(DestTraffic2VO traffic);
	
	@SQL("delete from tb_dest_traffic2 where dest_id =:1 and traffic_type = :2 ")
	public void deleteDestTraffic(int destId,int trafficType);

	@SQL("select * from tb_dest_traffic2 where parent_id=:1")
	public List<DestTraffic2VO> findListDestTrafficLevel(int parentId);
	
	@SQL("delete from tb_dest_traffic2 where traffic_id =:1 or parent_id = :1")
	public void deleteDestTrafficLevel2(int trafficId);
	
	@SQL("delete from tb_dest_traffic2 where traffic_id =:1")
	public void deleteDestTrafficLevel3(int trafficId);
	
	@SQL("select * from tb_dest_traffic2 where dest_id=:1 order by traffic_type asc")
	public List<DestTraffic2VO> findDestAllTraffices(int destId);
	
	

	/**
	 * 查询指定的交通信息和他的下一级交通信息
	 * @param trafficId
	 * @return
	 */
	@SQL("select * from tb_dest_traffic2 where traffic_id = :1 " +
			"union all " +
			"select * from tb_dest_traffic2 where parent_id = :1")
	public List<DestTraffic2VO> findTrafficEntity(int trafficId);
}
